#include <QDebug>
#include <QSet>

#include "PinAFList.h"
#include "errnum.h"

PinAFList::PinAFList()
    :u_afList(new QSet<QString>())
{
    /* 初始化 */
    u_afList->clear();

}

PinAFList::~PinAFList()
{
    u_afList->clear();
    delete u_afList;
    u_afList = nullptr;
}

int PinAFList::addAF(QString* afname)
{
    if (afname == nullptr) {
        // 处理 nullptr 的情况
        qDebug() << "afname is nullptr.";
        return ERR_1;
    }

    if (u_afList->contains(*afname)) {
        // 元素已存在于 set 中
        qDebug() << "Value already exists in the set.";
    } else {
        // 插入成功，value 不在 set 中
        u_afList->insert(*afname);
        qDebug() << "Value inserted successfully.";
    }

    return NONE_ERR;
}

QSet<QString>* PinAFList::afList()
{
    return u_afList;
}
